import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count:0,
    todos:[{id:1,text:'shopping',done:true},{id:1,text:'eat',done:false}]
  },
  mutations: {
    increment(state,data){
      state.count=state.count+data;
    }
  },
  actions: {
    SET_COUNT(context, data){
     setTimeout(()=>{
      context.commit('increment', data)
     },3000)
    }
  },
  modules: {
  },
  getters:{
    doneTodos:state=>{
       return state.todos.filter(todo=>todo.done)
    },
    doneTodosCount:(state,getters)=>{
       return getters.doneTodos.count;
    }
  }
})
